import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; class MyFrame extends Frame implements MouseListener { Label lbl; public MyFrame() { lbl=new Label("CCIT"); add(lbl); lbl.addMouseListener(this); Font fnt=new Font("TimesRoman",Font.BOLD,50); lbl.setFont(fnt); } public void mouseClicked (MouseEvent e){} public void mousePressed (MouseEvent e){} public void mouseReleased (MouseEvent e){} public void mouseEntered (MouseEvent e) { lbl.setForeground(Color.red); } public void mouseExited (MouseEvent e) { lbl.setForeground(Color.black); } } class demo { public static void main(String argvs[]) { MyFrame frm=new MyFrame(); frm.setSize(400,300); frm.setVisible(true); } }
import java.applet.Applet; import java.awt.event.*; public class MyApplet extends Applet implements MouseMotionListener { public void init() { this.addMouseMotionListener(this); } public void mouseMoved (MouseEvent e) { int x=e.getX(); int y=e.getY(); showStatus("X="+x+" Y="+y); } public void mouseDragged (MouseEvent e){} } //<applet code=MyApplet width=250 height=150 > < /applet>
import java.awt.Frame; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; class MyFrame extends Frame implements MouseMotionListener,MouseListener { int x1,y1; public MyFrame() { this.addMouseMotionListener(this); this.addMouseListener(this); } public void mouseClicked (MouseEvent e){} public void mouseEntered (MouseEvent e){} public void mouseExited (MouseEvent e){} public void mousePressed (MouseEvent e) { x1=e.getX(); y1=e.getY(); } public void mouseReleased (MouseEvent e){} public void mouseMoved (MouseEvent e){} public void mouseDragged (MouseEvent e) { Graphics g=this.getGraphics(); g.drawLine(x1,y1,e.getX(),e.getY()); x1=e.getX(); y1=e.getY(); } } class demo { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setSize(400,300); frm.setVisible(true); } }